package com.xjt.query.dao.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.xjt.query.dao.interf.HcCompanyInfoDao;
import com.xjt.query.dao.pojo.HcCompanyInfo;
import com.xjt.query.entity.LeadsQueryVo;

public class HcCompanyInfoDaoImpl extends SqlMapClientDaoSupport implements HcCompanyInfoDao {

    public int countCompanyInfo(LeadsQueryVo query) {
        Integer count = (Integer) getSqlMapClientTemplate().queryForObject("hc_company_info.countCompanyInfo", query);
        return count;
    }

    public Long insertHcCompanyInfo(HcCompanyInfo record) {
        Object newKey = getSqlMapClientTemplate().insert("hc_company_info.insertHcCompanyInfo", record);
        return (Long) newKey;
    }

    @SuppressWarnings("unchecked")
    public List<HcCompanyInfo> queryCompanyInfo(HcCompanyInfo info) {
        List<HcCompanyInfo> list = getSqlMapClientTemplate().queryForList("hc_company_info.queryCompanyInfo", info);
        return list;
    }

    @SuppressWarnings("unchecked")
    public List<HcCompanyInfo> queryCompanyInfoPaging(LeadsQueryVo query) {
        List<HcCompanyInfo> list = getSqlMapClientTemplate().queryForList("hc_company_info.queryCompanyInfoPaging",
                                                                          query);
        return list;
    }

    @Override
    public HcCompanyInfo selectCompanyInfoById(long id) {
        HcCompanyInfo info = new HcCompanyInfo();
        info.setId(id);
        List<HcCompanyInfo> list = queryCompanyInfo(info);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}
